package logic

import (
	"context"
	"gorm.io/gorm"
	"pro/models/mysql"

	"pro/prorpc/internal/svc"
	"pro/prorpc/prorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DoctorUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorUpdateLogic {
	return &DoctorUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DoctorUpdateLogic) DoctorUpdate(in *prorpc.DoctorUpdateRequest) (*prorpc.DoctorUpdateResponse, error) {
	// todo: add your logic here and delete this line
	doctor := mysql.Doctor{
		Model:     gorm.Model{ID: uint(in.DoctorId)},
		HeadImage: in.HeadImage,
		Name:      in.Name,
		Tel:       in.Tel,
		Ke:        in.Ke,
		Price:     float64(in.Price),
	}
	mysql.DB.Debug().Updates(&doctor)

	return &prorpc.DoctorUpdateResponse{
		DoctorId: int64(doctor.ID),
	}, nil
}
